#include "server.hpp"
#define HOST "127.0.0.1"
#define USER "root"
#define PASS "yxl233hhh"
#define DBNAME "gobang"
#define PORT 3306

void mysql_test()
{
     MYSQL *mysql = mysql_util::mysql_create(HOST,USER,PASS,DBNAME,PORT);
    const char *sql="insert stu values(null,'小黑',18,50,50,55);";
    bool ret = mysql_util::mysql_exec(mysql,sql);
    if(ret == false)
    {
        return ;
    }
    mysql_util::mysql_destroy(mysql);
}

void json_test()
{
    Json::Value root;
    root["姓名"] = "小明";
    root["年龄"] = 18;
    root["成绩"].append(88);
    root["成绩"].append(85.5);
    root["成绩"].append(89);
    std::string body;
    json_util::serialize(root,body);
    DLOG("%s",body.c_str());

    Json::Value val;
    json_util::unserialize(body,val);
    //逐个访问json：value中的数据
    std::cout<<"姓名： "<<val["姓名"].asString()<<std::endl;
    std::cout<<"年龄： "<<val["年龄"].asInt()<<std::endl;
    int sz = val["成绩"].size();
    for(int i=0;i<sz;i++)
    {
        std::cout<<"成绩： "<<val["成绩"][i].asFloat()<<std::endl;

    }
}

void str_test()
{
    std::string str = "123,123,25,,5,44,5";
    std::vector<std::string> arry;
    string_util::split(str,",",arry);
    for(auto s:arry)
    {
        DLOG("%s",s.c_str());
    }
}

void file_test()
{
    std::string filename = "./makefile";
    std::string str;
    file_util::read(filename,str);
    std::cout<<str<<std::endl;
}

void db_test()
{
    user_table ut(HOST,USER,PASS,DBNAME,PORT);
    Json::Value user;
     user["username"] = "xiaoming";

    
    bool ret = ut.login(user);
    if(ret == false)
    {
        std::cout<<"登陆失败"<<std::endl;
    }
    //bool ret = ut.select_by_id(2,user);
    // std::string body;
    // json_util::serialize(user,body);
    // std::cout<<body<<std::endl;
    //bool ret = ut.win(1);
    //bool ret = ut.win(1);
    //bool ret = ut.lose(1);


}

void online_test()
{
    online_manager om;
    wsserver_t::connection_ptr conn;
    uint64_t uid = 2;
    om.enter_game_room(uid,conn);
    if(om.is_in_game_room(uid))
    {
        DLOG("IN GAME HALL");
    }
    om.exit_game_room(uid);
    if(om.is_in_game_room(uid))
    {
        DLOG("IN GAME HALL");
    }
    else
    {
        DLOG("NOT IN GAME HALL");
    }
}

int main()
{
    // user_table ut(HOST,USER,PASS,DBNAME,PORT);
    // online_manager om;
    // room r(10,&ut,&om);
    // room_manager rm(&ut,&om);
    // room_ptr rp = rm.create_room(10,20);
    // matcher mc(&rm,&ut,&om);
    gobang_server gs(HOST,USER,PASS,DBNAME,PORT);
    gs.start(8085);
    return 0;
}